package com.qige.homework;

import java.math.BigDecimal;

public class homework9 {
    public static void main(String[] args) {
        System.out.println("原数字：23.23456789");
        BigHandleable2 bigHandleable2 = new BigHandleable2();
        String handleable = bigHandleable2.handleable("23.23456789");
        System.out.println("取整后: " + handleable);
        BigHandleable3 bigHandleable3 = new BigHandleable3();
        System.out.println("原数字：23.23456789");
        String handleable1 = bigHandleable3.handleable("23.23456789");
        System.out.println("保留4位小数，四舍五入后: " + handleable1);
    }
}
interface Handleable1{
    String handleable(String num);
}
class BigHandleable2 implements Handleable1 {
    @Override
    public String handleable(String num) {
        BigDecimal bigDecimal = new BigDecimal(num);
        BigDecimal divide = bigDecimal.divide(new BigDecimal("1"), 0, BigDecimal.ROUND_DOWN);
        String str = divide.toString();
        return str;
    }
}
class BigHandleable3 implements Handleable1 {
    @Override
    public String handleable(String num) {
        BigDecimal bigDecimal = new BigDecimal(num);
        BigDecimal divide = bigDecimal.divide(new BigDecimal("1"), 4, BigDecimal.ROUND_HALF_UP);
        String str = divide.toString();
        return str;
    }
}